package com.platform.service.impl;

import com.platform.annotation.SysLog;
import com.platform.base.BaseService;
import com.platform.common.Const;
import com.platform.common.ServerResponse;
import com.platform.dao.EnumMapper;
import com.platform.pojo.Enum;
import com.platform.service.IEnumService;
import com.platform.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * 枚举服务层
 */
@Service("iEnumService")
public class EnumServiceImpl extends BaseService implements IEnumService {


    /**
     * 根据类型查询
     * @param param
     * @return
     */
    @SysLog("枚举查询")
    @Cacheable(value = "SelectEnumByParam")
    public ServerResponse<List<Map>> selectByParam(Map param){
        List<Map> enumList = enumMapper.selectEnumByPamam(param);
        if(null != enumList && 0 < enumList.size()){
            return ServerResponse.createBySuccess(Const.Msg.SELECTSUCCESS,enumList);
        }
        return ServerResponse.createByErrorMessage(Const.Msg.SELECTERROR);
    }


    @SysLog("新增枚举")
    @CacheEvict(value = "SelectEnumByParam",allEntries=true)
    public ServerResponse<String> insert(Enum e){
        if(enumMapper.insert(e) > 0){
            return ServerResponse.createBySuccessMessage(Const.Msg.SAVESUCCESS);
        }
        return ServerResponse.createByErrorMessage(Const.Msg.SAVEERROR);
    }


    @SysLog("删除枚举")
    @CacheEvict(value = "SelectEnumByParam",allEntries=true)
    public ServerResponse<String> del(Integer id){
        if(enumMapper.deleteByPrimaryKey(id) > 0){
            return ServerResponse.createBySuccessMessage(Const.Msg.DELSUCCESS);
        }
        return ServerResponse.createByErrorMessage(Const.Msg.DELERROR);
    }

    @SysLog("更新枚举")
    @CacheEvict(value = "SelectEnumByParam",allEntries=true)
    public ServerResponse<String> update(Enum e){
        if(enumMapper.updateByPrimaryKey(e) > 0){
            return ServerResponse.createBySuccessMessage(Const.Msg.UPDATESUCCESS);
        }
        return ServerResponse.createByErrorMessage(Const.Msg.UPDATEERROR);
    }


}
